target = codesters.Sprite("triangle", 0, 150)
target.set_opacity(.5)
text = codesters.Text('target', 0, 130)
text.set_size(.8)
text.set_opacity(.8)
# stage.create_grid_overlay(line_separation, "line_color")
stage.create_grid_overlay(50, "grey")
sprite = codesters.Sprite("triangle")
sprite.set_speed(1)
try:
tval1 = sprite.get_y()
except:
tval1 = "DNE"
try:
tval2 = sprite.get_x()
except:
tval2 = "DNE"
try:
tval3 = sprite.get_rotation()
except:
tval3 = "DNE"
try:
tval4 = sprite.get_flip()
except:
tval4 = "DNE"
if tval1 == 150:
text.set_text(" ")
t1 = TestObjective()
t1.add_success(tval1 == 150, "Great Job!")
t1.add_failure(tval1 == 0, "Did you use Translate y?")
t1.add_failure(tval1 == 50, "Correct. Now change the number in translate y to reach the target.")
t1.add_failure(tval1 > 150, "Oops! Too far! Try again.")
t1.add_failure(tval1 < 150 and tval1 != 50 and tval1 != 0, "Oops! Not far enough! Try again.")
t1.add_failure(tval1 == "DNE", "Did you delete your sprite?")
t1.add_failure(tval2 != 0 and tval2 != "DNE", "Make sure you used Translate y in your code.")
t2 = TestObjective()
t2.add_success(tval3 == 0 or tval3 == "DNE", "Great job!")
t2.add_failure(tval3 > 0 and tval4 == False, "Oops! Did you add a rotation command?")
t3 = TestObjective()
t3.add_success(tval4 == False, "Great job!")
t3.add_failure(tval4 == True, "Oops! Did you use a reflection command?")
tester = TestManager()
tester.display_graphics = False
tester.add_test_list([t3, t2, t1])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)